<?php if(!defined('BASEPATH')) exit("Sorry, what you're looking not found.");
class C_user extends Nvl_Controller{
    function __construct(){
        parent::__construct();
        session_start();
		$this->__checkSession();
        $this->load->model('m_user');
    }

    function index(){
        $this->load->view('pages/v_user');
    }

    function get_list(){
        $pagenum = $this->input->get('pagenum');
        $pagesize = $this->input->get('pagesize');
		$start = $pagenum * $pagesize;
		$end = $start + $pagesize;
		$search_text = $this->input->get('search_text');
		$result = $this->m_user->get_list($start, $end, $search_text);
		echo $result;
    }
	
	function save(){
		$params = json_decode($this->input->post("params"));
		if($params->user_id == FALSE){
			$params->user_password = md5('123456');
		}
		$data = array(
			"user_name"=>$params->user_name,
			"user_password"=>$params->user_password,
			"user_usergroup_id"=>$params->usergroup_id,
			"user_aktif"=>$params->user_aktif
		);
		$result = $this->m_user->__save($data, $params->user_id);
		echo $result;
	}
	
	function delete(){
		$user_id = $this->input->numeric('user_id');
		$result = $this->m_user->__save(array('user_aktif'=>'0'), $user_id);
		echo $result;
	}
}